package card;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 故我
 * Date: 2024-01-30
 * Time: 14:36
 */
public class cardDemo {
    private static final String[] suites = {"♣", "■", "♥", "♠"};

    // 买一副牌
    public List<card> buyCard() {
        List<card> cards = new ArrayList<>();
        for (int i = 0; i < 4; i++) {
            for (int j = 1; j <= 13; j++) {
                card tmp = new card(suites[i], j);
                cards.add(tmp);
            }
        }
        return cards;
    }

    // 交换
    public void swap(List<card> cards, int i, int j) {
        card tmp = cards.get(i);
        cards.set(i, cards.get(j));
        cards.set(j, tmp);
    }

    // 洗牌
    public void Shuffle(List<card> cards) {
        Random random = new Random();
        for (int i = cards.size() - 1; i > 0; i--) {
            int index = random.nextInt(i); // [ )
            swap(cards, i, index);
        }
    }

    // 揭牌   三个人 每个人每人揭5张牌
    public void getCard(List<card> cardList) {
        List<List<card>> cards = new ArrayList<>();

        List<card> hand1 = new ArrayList<>();
        List<card> hand2 = new ArrayList<>();
        List<card> hand3 = new ArrayList<>();

        cards.add(hand1);
        cards.add(hand2);
        cards.add(hand3);

        for (int i = 0; i < 5; i++) {
            for (int j = 0; j < 3; j++) {
                card card1 = cardList.remove(0);
                // 放入hand中
                cards.get(j).add(card1);
            }
        }

        System.out.println(hand1);
        System.out.println(hand2);
        System.out.println(hand3);

        System.out.println(cardList);
    }
}
